#include "AnaDef.h"
#include "AnaAliDef.h"
#include "AliAnalysisTaskAODpkRaa.h"

void run(const TString fin)
{
  const TString taskname="AODpkRaa";
  printf("\n======> Task: %s File: %s\n", taskname.Data(), fin.Data());

  TChain * aodchain = new TChain("aodTree");
  aodchain->Add(fin);

  /*
  gSystem->AddIncludePath("-I$ALICE_ROOT/include");
  gSystem->Load("libANALYSISalice");
  gROOT->LoadMacro("AliAnalysisTaskAODpkRaa.cxx++");
  */

  AliAnalysisManager *mgr = new AliAnalysisManager();
  mgr->SetInputEventHandler(new AliAODInputHandler);

  AliAnalysisTaskAODpkRaa *task = new AliAnalysisTaskAODpkRaa;

  //not for AOD!!!
  //task->SelectCollisionCandidates(AliVEvent::kMB);

  mgr->AddTask(task);

  AliAnalysisDataContainer *cinput  = mgr->GetCommonInputContainer();
  mgr->ConnectInput(task,  0, cinput );

  const TString foutname=Form("xlu_%s",taskname.Data());

  AliAnalysisDataContainer *outlist1 = mgr->CreateContainer("xlu_tree",            TTree::Class(), AliAnalysisManager::kOutputContainer,foutname+"_tree.root");
  AliAnalysisDataContainer *outlist2 = mgr->CreateContainer("xlu_list",            TList::Class(), AliAnalysisManager::kOutputContainer,foutname+"_hist.root");

  //in AnalysisTaskSE, slot 0 reserved, must start from 1
  task->ConnectOutput(1, outlist1);
  task->ConnectOutput(2, outlist2);

  // Run the Analysis
  const Int_t nentries = 1e9;
  if(mgr->InitAnalysis()){  
    TStopwatch timer;
    timer.Start();
    mgr->StartAnalysis("local", aodchain, nentries);
    timer.Stop();
    timer.Print();
  }
}

int main(int argc, char *argv[])
{
  for(int ii=0; ii<argc; ii++){
    printf("%d: %s\n", ii, argv[ii]);
  }
  if(argc!=2){
    printf("argv!=2\n");exit(1);
  }

  run(argv[1]);

  return 0;
}
